package com.e7.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.e7.common.IPersistenceManager;
import com.e7.common.PersistenceManagerAware;
import com.e7.model.User;

@Repository("userDao")
public class UserDao implements PersistenceManagerAware {

	private IPersistenceManager manager;
	
	public Integer exists(User user) {
		return this.manager.exists(user);
	}

	public User findOne(String field, String value) {
		List<User> users = this.manager.find(User.class, field, value);
		if (users == null || users.size() < 1)
			return null;
		return users.get(0);
	}

	public boolean save(User user) {
		try {
			this.manager.save(user);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public void update(User user) {
		this.manager.update(user);
	}

	public void update(User user, String string, int i) {
		this.manager.update(user);
	}

	@Resource
	@Override
	public void setPersistenceManager(IPersistenceManager manager) {
		this.manager = manager;
	}
}
